﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Core.EventBus;
/// <summary>
/// 事件总线选项
/// </summary>
public class EventBusOptions : IConfigurableOptionsListener<EventBusOptions>
{
    /// <summary>
    /// 是否开启事件总线
    /// </summary>
    public bool IsEnableEventBus { get; set; }

    /// <summary>
    /// 事件数据保存天数
    /// </summary>
    public int EventDataSaveDay { get; set; } = 30;

    /// <summary>
    /// 最大处理线程数
    /// </summary>
    public int ProcessingThreadMaxCount { get; set; }

    /// <summary>
    /// 执行超时时间，超时后会重复执行
    /// </summary>
    public int ExecTimeOutSeconds { get; set; } = 60;


    public void OnListener(EventBusOptions options, IConfiguration configuration)
    {
        Type entityType = GetType();//获得该类的Type

        var dics = options.GetDictionary();
        foreach (var item in dics)
        {
            PropertyInfo propertyInfo = entityType.GetProperty(item.Key);
            propertyInfo.FieldSetValue(item.Key, item.Value as object);
        }
    }

    public void PostConfigure(EventBusOptions options, IConfiguration configuration)
    {
    }
}
